// 管理员类型枚举 - 与后端保持一致
export enum AdminType {
  SUPER_ADMIN = 'super_admin',
  SCHOOL_ADMIN = 'school_admin'
}

// 管理员登录响应DTO - 与后端保持一致的结构
export interface AdminLoginResponseDto {
  accessToken: string;
  admin: {
    id: string;
    username: string;
    name: string;
    email?: string;
    phone?: string;
    avatar?: string;
    adminType: AdminType;
    tenantIds?: string[]; // 可管理的租户列表
  };
}

// 前端用户信息类型 - 重构后的用户信息结构
export interface AdminUserInfo {
  id: string;
  username: string;
  name: string;
  email?: string;
  phone?: string;
  avatar?: string;
  adminType: AdminType;
  tenantIds?: string[]; // 可管理的租户ID列表
  currentTenant?: TenantInfo; // 当前选中的租户
  availableTenants?: TenantInfo[]; // 可用租户详细信息
}

// 租户信息类型
export interface TenantInfo {
  id: string;
  name: string;
  status: 'active' | 'inactive' | 'suspended';
  description?: string;
  logoUrl?: string;
  address?: string;
  contactPhone?: string;
  contactEmail?: string;
}

// 权限检查工具类
export class PermissionChecker {
  /**
   * 检查是否为超级管理员
   */
  static isSuperAdmin(adminType: AdminType): boolean {
    return adminType === AdminType.SUPER_ADMIN;
  }

  /**
   * 检查是否为学校管理员
   */
  static isSchoolAdmin(adminType: AdminType): boolean {
    return adminType === AdminType.SCHOOL_ADMIN;
  }

  /**
   * 检查是否有租户访问权限
   */
  static hasTenantAccess(adminType: AdminType, tenantIds: string[] | undefined, targetTenantId: string): boolean {
    if (this.isSuperAdmin(adminType)) {
      return true; // 超级管理员可访问所有租户
    }

    if (this.isSchoolAdmin(adminType)) {
      return tenantIds?.includes(targetTenantId) ?? false;
    }

    return false;
  }
}

// 权限指令绑定类型
export interface PermissionDirectiveBinding {
  adminTypes?: AdminType[];
  tenantId?: string;
}

// 路由元信息扩展接口
export interface RouteMetaWithPermission {
  title?: string;
  icon?: string;
  hidden?: boolean;
  requiresAuth?: boolean;
  adminTypes?: AdminType[]; // 允许的管理员类型
  requiresTenant?: boolean; // 是否需要租户上下文
}
